namespace WP7Contrib.Services.BingMaps.Model
{
    using Collections;
    using Common;
    using Common.Extensions;

    public class RouteLeg : BaseModel, ICloneable<RouteLeg>
    {
        private ObservableCollection<ItineraryItem> itineraryItems;

        public RouteLeg()
        {
            this.itineraryItems = new ObservableCollection<ItineraryItem>();
        }

        public ObservableCollection<ItineraryItem> ItineraryItems
        {
            get
            {
                return this.itineraryItems;
            }
            set
            {
                this.SetPropertyAndNotify(ref this.itineraryItems, value, () => this.ItineraryItems);
            }
        }

        public bool HasItineraryItems
        {
            get { return this.itineraryItems != null && this.itineraryItems.Count != 0; }
        }

        public RouteLeg ShallowClone()
        {
            return new RouteLeg {ItineraryItems = this.itineraryItems};
        }

        public RouteLeg DeepClone()
        {
            var result = new RouteLeg();

            if (this.HasItineraryItems)
            {
                var copy = new ObservableCollection<ItineraryItem>();
                this.itineraryItems.ForEach(i => copy.Add(i.DeepClone()));

                result.ItineraryItems = copy;
            }

            return result;
        }
    }
}